﻿using System;

namespace TI_BLE_HCI_ClientLib.DataEntities.Advertising
{
    public class IncompleteListOf16BitServiceUUIDsAdvertisingDataStructure : AdvertisingDataStructure
    {
        private ushort[] _serviceUUIDs;

        public ushort[] ServiceUUIDs
        {
            get { return _serviceUUIDs; }
            set { _serviceUUIDs = value; }
        }

        public IncompleteListOf16BitServiceUUIDsAdvertisingDataStructure(ushort[] serviceUUIDs)
            : base(AdvertisingDataStructureTypeEnum.IncompleteListOf16BitServiceClassUUIDs, convertWordArrayInByteArray(serviceUUIDs))
        {
            _serviceUUIDs = serviceUUIDs;
        }

        static byte[] convertWordArrayInByteArray(ushort[] wordArray)
        {
            var buf = new byte[2 * wordArray.Length];

            for(int i=0;i<wordArray.Length;i++)
            {
                buf[2 * i] = (byte)(wordArray[i] & 0xFF);
                buf[2 * i+1] = (byte)((wordArray[i]>>8) & 0xFF);
            }

            return buf;
        }
    }
}